
/***
 * 
 * 定开
 * 开放
 * 封闭
 * 静态工厂模式
 * 抽象工厂模式
 */

function getAFactory(type ){
    switch(type){
        case 1:
            return new Milk()
    }
}

getAFactory(1).getTaste()


const FruitEnum = {
    APPLE :"苹果",
    ORAGE : "橙子"
}

const DrinkEnum = {
    WINE:"酒",
    MILK:"牛奶"
}
const FactoryEnum = {
    COLOR_FACTORY:"COLOR_FACTORY",
    TASTE_FACTORY:"TASTE_FACTORY"
}
/**
 * 味道
 */
class ITaste{
    getTaste(){}
}

class Milk extends ITaste{
    getTaste(){
        return "香纯可口"
    }
}

class Wine extends ITaste{
    getTaste(){
        return "容易醉"
    }
}

/***
 * 颜色
 */
class IColor{
    getColor(){}
}

class Apple extends IColor{
    getColor(){
        return "红"
    }
}

class Orange extends IColor{
    getColor(){
        return "黄"
    }
}

class AbstractFactory{
    getTaste(name){}
    getColor(name){}
}

class TasteFactory{
    getTaste(name){
        if(name == DrinkEnum.MILK){
            return new Milk()
        }else if(name == DrinkEnum.WINE){
            return new Wine()
        }
        return null
    }
    getColor(name){
        return null
    }
}
class ColorFactory{
    getTaste(name){
        return null
    }
    getColor(name){
        if(name == FruitEnum.APPLE){
            return new Apple()
        }else if(name == FruitEnum.ORAGE){
            return new Orange()
        }
        return null
    }
}

/***
 * 工厂提供者
 */
function FactoryProducter(factoryName){
    switch (factoryName) {
        case FactoryEnum.COLOR_FACTORY:
            return new ColorFactory()
        case FactoryEnum.TASTE_FACTORY:
            return TasteFactory()
        default:
            return null;
    }
}
const color = FactoryProducter(FactoryEnum.COLOR_FACTORY).getColor(FruitEnum.APPLE).getColor()
console.log(color)

